package com.lzz.bottomencapsulation.adapter;
import android.view.View;
import android.view.ViewGroup;
import java.util.List;
import androidx.viewpager.widget.PagerAdapter;

/**
 * 可以展示图片
 */
public class ViewPageAdapter extends PagerAdapter {
    private List<View> mListViews;

    public ViewPageAdapter(List<View> mListViews) {
        this.mListViews = mListViews;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView(mListViews.get(position));//删除页卡
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        if (mListViews.get(position).getParent() == null) {
            container.addView(mListViews.get(position));
        } else {
            ((ViewGroup) mListViews.get(position).getParent()).removeView(mListViews.get(position));
            container.addView(mListViews.get(position));
        }
        return mListViews.get(position);
    }

    @Override
    public int getCount() {
        return mListViews.size();
    }

    @Override
    public boolean isViewFromObject(View arg0, Object arg1) {
        return arg0 == arg1;
    }
}
